package com.emip.servlet.baseinfo;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;


import com.emip.bean.MonitorTypeBean;
import com.emip.config.SysParams;
import com.emip.pojo.Table;
import com.emip.service.MonitorTypeService;
import com.emip.util.TableFormat;


@Controller
@RequestMapping(value="/base/monitorType")
public class MonitorTypeAction {

	@Autowired
	MonitorTypeService monitorTypeService;
	
	@RequestMapping(value="/management")
	public String index() {		
		return "/baseInfo/MonitorTypeManagement";
	}
	
	@RequestMapping(value="/getAllMonitorTypes")
	public @ResponseBody Table<MonitorTypeBean> getAllMonitorTypes() {
		List<MonitorTypeBean> result = monitorTypeService.getAll();
		int records = result.size();
		int totalPages = records / SysParams.gridDefinedRowNumber + 1;
		return new TableFormat<MonitorTypeBean>().formTable(totalPages, 1, records, result);
	}
	
	@RequestMapping(value="/getMonitorTypeByID",method=RequestMethod.POST, headers="Accept=application/json")
	public @ResponseBody MonitorTypeBean getMonitorTypeByID(@RequestParam("eid") int eid) {
		return monitorTypeService.getMonitorTypeByID(eid);
	}
	
	@RequestMapping(value="/addMonitorType",method=RequestMethod.POST)
	public @ResponseBody MonitorTypeBean addMonitorType(@RequestParam("eTypeID") String typeID, @RequestParam("eName") String name) {
		return monitorTypeService.addMonitorType(typeID, name);
	}
	
	@RequestMapping(value="/updateMonitorType",method=RequestMethod.POST)
	public @ResponseBody MonitorTypeBean updateMonitorType(@RequestParam("eID") int id, @RequestParam("eTypeID") String typeID, @RequestParam("eName") String name) {
		return monitorTypeService.updateMonitorType(id, typeID, name);
	}
	
	@RequestMapping(value="/deleteMonitorType",method=RequestMethod.POST)
	public @ResponseBody String deleteMonitorType(@RequestParam("eID") int id) {
		monitorTypeService.deleteMonitorType(id);
		return "success";
	}
	
	@RequestMapping(value="/getAllMonitorTypesObj") 
	public @ResponseBody List<MonitorTypeBean> getAllMonitorTypesObj() {
		return monitorTypeService.getAll();
	}
}
